#pragma once
#include <set>
#include <mutex>
#include <vector>
#include <string>
#include <atlcomcli.h>
#include <dshow.h>
#include <comutil.h>
#include <mmdeviceapi.h>
#include <Functiondiscoverykeys_devpkey.h>

class VideoDeviceInfo 
{
public:
    std::string strFriendName;
    std::string strUniqueID;
    std::set<std::tuple<int, int,int>> setResolutions;
};

class AudioDeviceInfo
{
public:
    std::string strFriendName;
    std::string strUniqueID;
};

class DeviceinfoDs
{
public:
    ~DeviceinfoDs();
    static DeviceinfoDs& GetInstance();
    void UpdateDevice();
    void GetVideoInputDevice(std::vector<std::tuple<std::string,std::string>>& info);
    void GetAudioInputDevice(std::vector<std::tuple<std::string, std::string>>& info);
    void GetAudioOutputDevice(std::vector<std::tuple<std::string, std::string>>& info);
    int GetVideoInputDeviceNameByIndex(const int index, std::string& strFriendName, std::string& strUniqueId);
    int GetAudioInputDeviceNameByIndex(const int index, std::string& strFriendName, std::string& strUniqueId);
    int GetMaxResolutionsByUniqueId(const std::string& strUniqueID,int& w,int& h, int& fps);
    int GetAllResolutionsByUniqueId(const std::string& strUniqueID, std::set<std::tuple<int, int, int>>& setResolutions);
private:
    DeviceinfoDs();
    void UpdateVideoInputDeviceInfo();
    void UpdateAudioInputDeviceInfo();
    void UpdateAudioOutputDeviceInfo();
    std::mutex mutex;
    std::vector<VideoDeviceInfo> VideoInputDeviceInfos;
    std::vector<AudioDeviceInfo> AudioInputDeviceInfos;
    std::vector<AudioDeviceInfo> AudioOutputDeviceInfos;
    CComPtr<ICreateDevEnum>_dsDevEnum;
    CComPtr<IGraphBuilder> pGraph;
    CComPtr<ICaptureGraphBuilder2> pBuilder;
};

